#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "DeviceAddModel.h"
#include <QQmlContext>
#include <QQmlEngine>
#include <QUrl>
#include <QDir>
#include <QDebug>
static void prepareApp()
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QCoreApplication::setOrganizationName("JaredTao");
    QCoreApplication::setOrganizationDomain("https://JaredTao.gitee.io");
    QCoreApplication::setApplicationName("TableEdit");
}

int main(int argc, char *argv[])
{
    prepareApp();
#ifdef _DEBUG
    qSetMessagePattern("[%{time h:mm:ss.zzz} %{file} row(%{line}) %{function}] %{message}");
#endif

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;

    engine.rootContext()->setContextProperty("qmlPath", qmlPath);
    engine.rootContext()->setContextProperty("imgPath", imgPath);
    const auto appPath = QDir::cleanPath(app.applicationDirPath());
    engine.rootContext()->setContextProperty("appPath", appPath);

    DeviceAddModel model;
    const QUrl url(qmlPath + QStringLiteral("main.qml"));
    engine.rootContext()->setContextProperty("deviceAddModel", &model);
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
        &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}
